package aspirecn.project3.mapper;


import aspirecn.project3.model.User;
import org.apache.ibatis.annotations.*;
import org.junit.runners.Parameterized;

import java.util.List;


@Mapper
public interface UserMapper {

    @Insert("INSERT INTO `user` " +
            "(TYPE,NAME,SEX,AGE,PHONE,EMAIL,PASSWORD,DEVICE_INFORMATION,SOURCE_CHANNEL,POINT)" +
            "values " +
            "(#{type},#{name},#{sex},#{age},#{phone},#{email},#{password},#{deviceInformation},#{sourceChannel},#{point})")
    void addUser(User user);


//    @Select("select * from user where ID = #{id}")
//    //id,type,name,sex,age,phone,email,password,deviceInformation,sourceChannel,point,reg,createTime,updateTime,status"
//    User getUserById(Long id);


    @Select("select " +
            "id " +
            "from " +
            "user " +
            "where " +
            "PHONE = #{keyword}")
    Long getUserByPhone(String keyword);

    @Select("select " +
            "id " +
            "from " +
            "user " +
            "where " +
            "EMAIL = #{keyword}")
    Long getUserByEmail(String keyword);
    @Select("SELECT * FROM user WHERE NAME LIKE CONCAT('%',#{keyword},'%')   LIMIT #{page}, #{size}")
    List<User> getUserByName(@Param("page") Integer page, @Param("size") Integer size, @Param("keyword") String keyword);
    @Select("SELECT * FROM user LIMIT #{page}, #{size}")
    List<User> getUserByPage(@Param("page") Integer page, @Param("size") Integer size);
    @Select("SELECT * FROM user where ID=#{id}")
    User getUserById(@Param("id") Long id);
    @Select("select count(*) from user")
    Long getTotal();
    @Delete("delete from user" +
            " where id = #{id}")
    int deleteByPrimaryKey(Integer id);

    @Insert("INSERT INTO `user` " +
            "(TYPE,NAME,SEX,AGE,PHONE,EMAIL,PASSWORD,DEVICE_INFORMATION,SOURCE_CHANNEL,POINT)" +
            "values " +
            "(#{user.type},#{user.name},#{user.sex},#{user.age},#{user.phone},#{user.email},#{user.password}" +
            ",#{user.deviceInformation},#{user.sourceChannel},#{user.point})")
    int insertUser(@Param("user") User user);

    @Select("select * from user limit #{num},1")
    User getRandomUser(Integer num);
    @Update("update user set TYPE=#{user.type} and and NAME=#{user.name},SEX=#{user.sex} and AGE=#{user.age" +
            "}and DEVICE_INFRMATION = #{user.deviceInformation} and SOURCE_CHANNEL= " +
            "#{user.sourceChannel} and POINT=#{user.point}")
    Integer alterUser(User user);
}
